home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-09 | 7.1 KB | 222 lines | [TEXT/R*ch] |
- // ===========================================================================
- // File: CTargeterBorder.cp
- // Version: 1.0 - Feb 1, 1996
- // Author: Mike Shields (mshields@inconnect.com)
- //
- // Copyright ©1996 Mike Shields. All rights reserved.
- // I hereby grant users of CTargeterBorder permission to use it (or any modified
- // version of it) in applications (or any other type of Macintosh software
- // like extensions -- freeware, shareware, commercial, or other) for free,
- // subject to the terms that:
- //
- // (1) This agreement is non-exclusive.
- //
- // (2) I, Mike Shields, retain the copyright to the original source code.
- //
- // These two items are the only required conditions for use. However, I do have
- // an additional request. Note, however, that this is only a request, and
- // that it is not a required condition for use of this code.
- //
- // (1) That I be given credit for CTargeterBorder code in the copyrights or
- // acknowledgements section of your manual or other appropriate documentation.
- //
- //
- // I would like to repeat that this last item is only a request. You are prefectly
- // free to choose not to do any or all of them.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- // ===========================================================================
- // CTargeterBorder.h <- double-click + Command-D to see class declaration
- //
- // Class providing a "focus box" around a pane
-
- #include "CTargeterBorder.h"
-
- #include <UDrawingState.h>
- #include <LStream.h>
- #include <URegions.h>
-
- #include "CTargetable.h"
-
- #pragma mark === Construction & Destruction ===
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::CreateFromStream
- //----------------------------------------------------------------------------------------
- // Static function registered with URegistrar to create a TargeterBorder from the data
- // in a stream
- CTargeterBorder* CTargeterBorder::CreateFromStream(LStream* inStream)
- {
- return (new CTargeterBorder(inStream));
- }
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::CTargeterBorder
- //----------------------------------------------------------------------------------------
- // Default Contructor
- CTargeterBorder::CTargeterBorder()
- {
- mTarget = nil;
- mIsTargeted = false;
- }
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::CTargeterBorder
- //----------------------------------------------------------------------------------------
- // Construct from the data in a Stream
- CTargeterBorder::CTargeterBorder(LStream* inStream)
- : LView(inStream)
- {
- mTarget = nil;
- mIsTargeted = false;
-
- inStream->ReadData(&mTargetedPaneID, sizeof(PaneIDT));
- }
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::~CTargeterBorder
- //----------------------------------------------------------------------------------------
- // Destructor
- CTargeterBorder::~CTargeterBorder()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::FinishCreateSelf
- //----------------------------------------------------------------------------------------
- // Set up our view so that we can be notified when the targeted pane becomes the target.
- void CTargeterBorder::FinishCreateSelf(void)
- {
- mTarget = dynamic_cast<CTargetable*>(this->FindPaneByID(mTargetedPaneID));
- SignalIf_(mTarget == nil);
-
- mTarget->SetTargeterBox(this);
- if ( mTarget->IsTargeted() )
- this->ShowFocus();
- else
- this->HideFocus();
- }
-
- #pragma mark === Drawing ===
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::DrawSelf
- //----------------------------------------------------------------------------------------
- // Draw the targeter box outline
- void CTargeterBorder::DrawSelf()
- {
- Rect frame;
- if ( mIsTargeted && CalcLocalFrameRect(frame) )
- {
- ApplyForeAndBackColors();
- ::PenNormal();
- ::PenSize(2, 2);
- ::FrameRect(&frame);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::Refresh
- //----------------------------------------------------------------------------------------
- // Invalidate the area occupied by a TargeterBorder so it will redraw during
- // the next Update event
- void CTargeterBorder::Refresh()
- {
- Rect frame;
- if ( IsVisible() &&
- CalcPortFrameRect(frame) &&
- (mSuperView != nil) )
- {
- Rect revealed;
- mSuperView->GetRevealedRect(revealed);
- if (::SectRect(&frame, &revealed, &revealed))
- {
- RgnHandle boxRgn = GetBoxRegion(frame, revealed);
- InvalPortRgn(boxRgn);
- ::DisposeRgn(boxRgn);
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::DontRefresh
- //----------------------------------------------------------------------------------------
- // Validate the area occupied by a TargeterBorder so it won't redraw during
- // the next Update event
- void CTargeterBorder::DontRefresh(Boolean inOKIfHidden)
- {
- Rect frame;
- if ( (IsVisible() || inOKIfHidden) &&
- CalcPortFrameRect(frame) &&
- (mSuperView != nil) )
- {
- Rect revealed;
- mSuperView->GetRevealedRect(revealed);
- if (::SectRect(&frame, &revealed, &revealed))
- {
- RgnHandle boxRgn = GetBoxRegion(frame, revealed);
- ValidPortRgn(boxRgn);
- ::DisposeRgn(boxRgn);
- }
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • GetBoxRegion
- // ---------------------------------------------------------------------------
- // Pass back a region defining a TargeterBorder. A TargeterBorder is a hollow
- // rectangular region. Clip region so that it is within the revealed rect.
- //
- // Creates a new region which the caller must dispose.
- RgnHandle CTargeterBorder::GetBoxRegion(const Rect &inFrame, const Rect &inRevealed) const
- {
- RgnHandle boxRgn = ::NewRgn();
- ::OpenRgn();
- Rect r = inFrame;
- ::FrameRect(&r); // Outer edge of box
- ::InsetRect(&r, 2, 2);
- ::FrameRect(&r); // Inner edge of box
- ::CloseRgn(boxRgn);
-
- // Clip to revealed rect
- RgnHandle revealedRgn = ::NewRgn();
- ::RectRgn(revealedRgn, &inRevealed);
- ::SectRgn(boxRgn, revealedRgn, boxRgn);
- ::DisposeRgn(revealedRgn);
-
- return boxRgn;
- }
-
- #pragma mark === Focus Management ===
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::ShowFocus
- //----------------------------------------------------------------------------------------
- // A TargeterBorder is being shown
- void CTargeterBorder::ShowFocus()
- {
- if ( !mIsTargeted )
- {
- mIsTargeted = true;
- Refresh();
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CTargeterBorder::HideFocus
- //----------------------------------------------------------------------------------------
- // A TargeterBorder is being hidden
- void CTargeterBorder::HideFocus()
- {
- if ( mIsTargeted )
- {
- mIsTargeted = false;
- Refresh();
- }
- }
-
-
-